package kyuu.acshmily.comment
{
	public class CommentValidator
	{
		private static var _keywords:Array = null;
		public function CommentValidator(){}

		/**
		 * 初始化
		 */
		public static function init(filterXML:XML):void{
			var kwList:XMLList = filterXML.child("keyword");
			if(_keywords == null)
				_keywords = new Array(kwList.length());

			for(var i:int=0; i<kwList.length(); i++)
				_keywords[i] = kwList[i][0].toString();
		}

		/**
		 * 检查语句是否包含关键字
		 */
		public static function check(text:String):Boolean{
			if(_keywords == null) return false;

			for(var i:int=0; i<_keywords.length; i++){
				var kw:String = _keywords[i] as String;
				if(text.indexOf(kw) >= 0) return false;
			}
			return true;
		}
	}
}